public class Ex5_27{
	public static void main(String[] args){
		int count = 0;
		int i = 2;
		while (count <= 100){
			if (isPrime(i) && !isPalindrome(i)){
				int j = reverse(i);
				if (isPrime(j)){
					System.out.printf("%6d", i);
					if (++count % 10 == 0)
						System.out.printf("\n");
				}
			}
			i++;
		}
		System.out.printf("\n");
	}

	public static int reverse(int number){
		int n = number;
		int s = 0;
		while (n != 0){
			int d = n % 10;
			s = s * 10 + d;
			n /= 10;
		}
		return s;
	}

	public static boolean isPrime(int number){
		boolean yes = true;
		for (int i = 2; i <= number/2; i++){
			if (number % i == 0){
				yes = false;
				break;
			}
		}
		return yes;
	}

	public static boolean isPalindrome(int number){
		int n = number;
		int s = 0;
		while (n != 0){
			int d = n % 10;
			s = s * 10 + d;
			n /= 10;
		}
		if (s == number)
			return true;
		else
			return false;
	}
}